// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0

export component TestCase inherits Window {
    width: 400phx;
    height: 600phx;

    input1 := TextInput {
        y: 0px;
        width: parent.width;
        height: 200phx;
    }

    input2 := TextInput {
        y: 200phx;
        width: parent.width;
        height: 200phx;
    }

    input3 := TextInput {
        y: 400phx;
        width: parent.width;
        height: 200phx;
        read-only: true;
    }

    out property<bool> input1_focused: input1.has_focus;
    out property<string> input1_text: input1.text;
    out property<bool> input2_focused: input2.has_focus;
    out property<string> input2_text: input2.text;
    out property<bool> input3_focused: input3.has_focus;
    in-out property input2_enabled <=> input2.enabled;
}

/*
```rust
use slint::private_unstable_api::re_exports::{InputMethodRequest, InputType, MouseCursor};

let instance = TestCase::new().unwrap();
assert!(!instance.get_input1_focused());
assert!(!instance.get_input2_focused());
assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.ime_requests.take()).len(), 0);

slint_testing::send_mouse_click(&instance, 150., 100.);
assert!(instance.get_input1_focused());
assert!(!instance.get_input2_focused());
let mut ime_requests = slint_testing::access_testing_window(instance.window(), |window| window.ime_requests.take()).into_iter();
assert!(matches!(ime_requests.next(), Some(InputMethodRequest::Enable(props)) if props.input_type == InputType::Text));
assert!(matches!(ime_requests.next(), Some(InputMethodRequest::Update(..))));
assert!(ime_requests.next().is_none());
assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Text);

slint_testing::send_keyboard_string_sequence(&instance, "Only for field 1");
assert_eq!(instance.get_input1_text(), "Only for field 1");
assert_eq!(instance.get_input2_text(), "");

slint_testing::access_testing_window(instance.window(), |window| window.ime_requests.take());
slint_testing::send_mouse_click(&instance, 150., 300.);
assert!(!instance.get_input1_focused());
assert!(instance.get_input2_focused());
let mut ime_requests = slint_testing::access_testing_window(instance.window(), |window| window.ime_requests.take()).into_iter();
assert!(matches!(ime_requests.next(), Some(InputMethodRequest::Disable)));
assert!(matches!(ime_requests.next(), Some(InputMethodRequest::Enable(props)) if props.input_type == InputType::Text));
assert!(matches!(ime_requests.next(), Some(InputMethodRequest::Update(..))));
assert!(ime_requests.next().is_none());


slint_testing::send_keyboard_string_sequence(&instance, "Only for field 2");
assert_eq!(instance.get_input1_text(), "Only for field 1");
assert_eq!(instance.get_input2_text(), "Only for field 2");

slint_testing::access_testing_window(instance.window(), |window| window.ime_requests.take());
slint_testing::send_mouse_click(&instance, 150., 500.);
assert!(!instance.get_input1_focused());
assert!(!instance.get_input2_focused());
assert!(instance.get_input3_focused());
let mut ime_requests = slint_testing::access_testing_window(instance.window(), |window| window.ime_requests.take()).into_iter();
assert!(matches!(ime_requests.next(), Some(InputMethodRequest::Disable)));
assert!(ime_requests.next().is_none());
assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Text);
```

```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
assert(!instance.get_input1_focused());
assert(!instance.get_input2_focused());

slint_testing::send_mouse_click(&instance, 150., 100.);
assert(instance.get_input1_focused());
assert(!instance.get_input2_focused());

slint_testing::send_keyboard_string_sequence(&instance, "Only for field 1");
assert_eq(instance.get_input1_text(), "Only for field 1");
assert_eq(instance.get_input2_text(), "");

slint_testing::send_mouse_click(&instance, 150., 300.);
assert(!instance.get_input1_focused());
assert(instance.get_input2_focused());

slint_testing::send_keyboard_string_sequence(&instance, "Only for field 2");
assert_eq(instance.get_input1_text(), "Only for field 1");
assert_eq(instance.get_input2_text(), "Only for field 2");
```

```js
var instance = new slint.TestCase();
assert(!instance.input1_focused);
assert(!instance.input2_focused);

slintlib.private_api.send_mouse_click(instance, 150., 100.);
assert(instance.input1_focused);
assert(!instance.input2_focused);

slintlib.private_api.send_keyboard_string_sequence(instance, "Only for field 1");
assert.equal(instance.input1_text, "Only for field 1");
assert.equal(instance.input2_text, "");

slintlib.private_api.send_mouse_click(instance, 150., 300.);
assert(!instance.input1_focused);
assert(instance.input2_focused);

slintlib.private_api.send_keyboard_string_sequence(instance, "Only for field 2");
assert.equal(instance.input1_text, "Only for field 1");
assert.equal(instance.input2_text, "Only for field 2");
```


```rust
// Test for issue #8626:  disabled TextInputs should not be focusable
let instance = TestCase::new().unwrap();
assert!(instance.get_input2_enabled());
instance.set_input2_enabled(false);
assert!(!instance.get_input1_focused());
assert!(!instance.get_input2_focused());
assert!(!instance.get_input3_focused());
slint_testing::send_keyboard_string_sequence(&instance, "\t");
assert!(instance.get_input1_focused());
assert!(!instance.get_input2_focused());
assert!(!instance.get_input3_focused());
slint_testing::send_keyboard_string_sequence(&instance, "\t");
assert!(!instance.get_input1_focused());
assert!(!instance.get_input2_focused());
assert!(instance.get_input3_focused());
```
*/
